package 力扣日常刷题.木22二月.第11天217;

/**
 * @author 帅小伙
 * @date 2022/2/17
 * @description
 * 横向比较
 */
public class Demo83最长公共前缀 {


    public String longestCommonPrefix(String[] strs) {
        if (strs == null || strs.length == 0) return "";
        int length = strs[0].length();
        int n = strs.length;
        for (int i = 0; i < length; i++) {
            char c = strs[i].charAt(i);
            for (int j = 1; j < n; j++) {
                if(i == strs[j].length() || strs[j].charAt(i)!= c) {
                    return strs[0].substring(0,i);
                }
            }
        }
        return strs[0];
    }
}
